package com.longge;

public class RemoveNthFromEnd {

    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode dummy = new ListNode(-1);
        ListNode p1 = dummy, p2 = dummy;
        dummy.next = head;
        n = n + 1;
        for (int i = 0; i < n; i++) {
            p1 = p1.next;
        }
        while (p1 != null) {
            p1 = p1.next;
            p2 = p2.next;
        }
        p2.next = p2.next.next;
        return dummy.next;

    }

    public static void main(String[] args) {
        System.out.println(null==null);
    }
}
